{include file="public/header" /}

<style type="text/css">
    
    .brand_btn{
        display: inline-block;
        border: none;
        padding: 0px 12px;
        height: 34px;
        line-height: 34px;
        border-radius: 3px;
        background-color: #419dfd;
        color: #fff!important;
        vertical-align: middle;
        text-align: center;
        cursor: pointer;
        font-size: 13px;
        margin-left: 747px;
        margin-bottom: -124px;
    }
</style>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>品牌管理</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <div class="fixed-empty"></div>

    <form method="get" name="formSearch" id="formSearch">

        <a href="{:url('Nquipment/brand_add',['id'=>$equipment_id])}" class="brand_btn">新增品牌</a>
        
        <div class="ds-search-form">
            <dl>
                <dt>品牌名称</dt>
                <dd><input type="text" value="{$Request.param.brand_name}" name="brand_name" class="txt"></dd>
            </dl>
            <dl>
                <dt>题库名称</dt>
                <dd><input type="text" value="{$Request.param.question_name}" name="question_name" class="txt"></dd>
            </dl>
            <dl>
                <dd><input type="submit" class="btn btn-small" value="{$Think.lang.ds_search}"></dd>

                {if $brand_name != '' || $question_name != ''}
                <dd><input type="button" id="celsearch" class="btn btn-small" value="取消搜索"></dd>
                {/if}
                <script>
                    // todo 取消搜索
                    $("#celsearch").click(function (){
                        $("[name='brand_name']").val('');
                        $("[name='question_name']").val('');
  
                        $('#formSearch').submit()
                    })
                </script>
            </dl>

            <div class="btn_group">
            </div>
        </div>
    </form>
    <table class="ds-default-table">
        <thead>
        <tr class="thead">
            <th class="w48">序号</th>
            <th>品牌名称</th>
            <th>题库名称</th>
            <th>安装工时</th>
            <th>拆移工时</th>
            <th class="w100">创建时间</th>
            <th class="w100 ">更新时间</th>
            <th class="w200 align-center">{$Think.lang.ds_handle}</th>
        </tr>
        <tbody>
        {notempty name="equipment_list"}
        {foreach name="equipment_list" item="question" key="key"}
        <tr id="ds_row_{$question.equipment_brand_id}">
            <td>{$key+1}</td>
            <td>{$question.brand_name}</td>
            <td>
                <p>{$question.question_name}</p>
            </td>
            <td>{$question.installation_hours}</td>
            <td>{$question.dismantling_hours}</td>
            <td>{$question.brand_created_at}</td>
            <td>{$question.brand_updated_at}</td>
            <td>
                <a href="{:url('Nquipment/brand_edit',['id'=>$question.equipment_brand_id])}" class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.ds_edit}</a>

                <a href="javascript:void(0);"
                   onclick="ds_ajaxget_confirm('{:url('Nquipment/equipment_brand_del',['id'=>$question.equipment_brand_id])}','确定要删除吗？');"
                   class="dsui-btn-del"><i class="iconfont"></i>删除</a>
            </td>
        </tr>
        {/foreach}
        {else /}
        <tr class="no_data">
            <td colspan="10">{$Think.lang.ds_no_record}</td>
        </tr>
        {/notempty}
        </thead>
    </table>
    {$show_page}
</div>
<script src="{$Think.ADMIN_SITE_ROOT}/js/question.js"></script>
<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript">

    function getGcId1(gc_id1, select_id)
    {
        var select_od = select_id;
        $.ajax({
            type : "GET",
            contentType: "application/json;charset=UTF-8",
            url : ADMINSITEURL+"/Question/getClass.html?gc_id=" + gc_id1,
            success : function(result) {
                result = JSON.parse( result );
                var html = '<option value="">选择分类</option>';
                for(var i=0;i<result.length;i++){
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    } else {
                        html += '<option value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    }
                }
                $('#search_gc_id2').html(html)
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }

    function getGcId2(gc_id1, select_id)
    {
        $.ajax({
            type : "GET",
            contentType: "application/json;charset=UTF-8",
            url : ADMINSITEURL+"/Question/getClass.html?gc_id=" + gc_id1,
            success : function(result) {
                result = JSON.parse( result );
                var html = '<option value="">选择分类</option>';
                for(var i=0;i<result.length;i++){
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    } else {
                        html += '<option value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    }
                }
                $('#search_gc_id3').html(html)
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
    //获取下级分类
    $('#search_gc_id1').on('change',function () {
        var gc_id1 = $(this).val();
        getGcId1(gc_id1)
    })

    $('#search_gc_id2').on('change',function () {
        var gc_id2 = $(this).val();
        getGcId2(gc_id2)
    })
</script>
{if $Request.param.search_gc_id1}
<script>

    // 编辑初始化，处理分类选中的问题
        var gc_id1 = '{$Request.param.search_gc_id1}';
        var gc_id2 = '{$Request.param.search_gc_id2}';
        var gc_id3 = '{$Request.param.search_gc_id3}';
        getGcId1(gc_id1, gc_id2)
        getGcId2(gc_id2, gc_id3)
</script>
{/if}
